package com.hlwxy.ssm.controller;


import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiProcessinstanceListidsRequest;
import com.dingtalk.api.response.OapiProcessinstanceListidsResponse;
import com.hlwxy.ssm.service.DingTalkService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

@RequestMapping("/dingtalk")
@RestController
public class DingTalkController {

    //请假
    String key1="PROC-3JYJVR1V-8AZVUMZPQGK5O37675UJ3-1GC2YAIJ-2";
    //出差
    String key2="PROC-F2E12DC0-9D9E-4B03-81B6-F49025B59BA0";
    //外出
    String key3="PROC-A1DBF454-EADA-485D-9938-70F0C976390B";
    //补卡申请
    String key4="PROC-1ABF577E-5437-4A16-91F6-83F4F0D9B8C4";
    private static   Long cursor=1L;

    @Autowired
    private DingTalkService dingTalkService;

    @RequestMapping()
    ModelAndView index() {
        return new ModelAndView("index");
    }

    @ResponseBody
    @RequestMapping("/list")
    List<Map<String, Object>> list(String ddtype,String pag,String stime,String etime) throws Exception{
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if(""==stime || null==stime){
            stime=simpleDateFormat.format(new Date());
        }
        if(""==etime || null==etime){
            etime=simpleDateFormat.format(new Date());
        }
        if("".equals(ddtype) || null==ddtype){
            ddtype=key4;
        }
        return dingTalkService.findAllData(ddtype,Long.parseLong(pag),stime,etime);
    };


    @ResponseBody
    @RequestMapping("/tb")
    void tb(String ddtype,String pag,String stime,String etime) throws Exception{

         dingTalkService.getAllDataBy4();
    };
}
